var warningData = [
  {
    alarm_name: "温度状态为未识别",
    res_name: "LK-Cluster-A2-403-E07F050607",
    res_ip: "10.226.26.214",
    starttime: "2024-12-20 17:16:10",
    updatetime: "2025-01-21 15:56:05",
    level: "中等",
  },
  {
    alarm_name: "Ping连通性异常",
    res_name: "LK-A2-403-C19-RGS6250-TOR-1-A",
    res_ip: "10.242.101.20",
    starttime: "2024-12-21 17:16:10",
    updatetime: "2025-01-21 15:56:05",
    level: "重要",
  },
  {
    alarm_name: "内存条状态为未识别",
    res_name: "JX-2017-HGT-X4-H06-PC",
    res_ip: "10.226.26.214",
    starttime: "2024-12-22 17:16:10",
    updatetime: "2025-01-21 15:56:05",
    level: "重要",
  },
  {
    alarm_name: "风扇状态为未识别",
    res_name: "JX-2017-HGT-X4-H06-PC",
    res_ip: "10.226.26.214",
    starttime: "2024-12-23 17:16:10",
    updatetime: "2025-01-21 15:56:05",
    level: "一般",
  },
  {
    alarm_name: "连通性为不连通",
    res_name: "JX-2015-HGT-X6-D09-PC-01",
    res_ip: "192.168.1.111",
    starttime: "2024-12-24 17:16:10",
    updatetime: "2025-01-21 15:56:05",
    level: "中等",
  },
  {
    alarm_name: "Agent或者SNMP服务连接异常",
    res_name: "JX-2017-HGT-X4-H06-PC",
    res_ip: "10.226.26.214",
    starttime: "2024-12-25 17:16:10",
    updatetime: "2025-01-21 15:56:05",
    level: "重要",
  },
  {
    alarm_name: "风扇状态为未识别",
    res_name: "JX-2017-HGT-X4-H06-PC",
    res_ip: "10.226.26.214",
    starttime: "2024-12-26 17:16:10",
    updatetime: "2025-01-21 15:56:05",
    level: "一般",
  },
  {
    alarm_name: "风扇状态为未识别",
    res_name: "JX-2017-HGT-X4-H06-PC",
    res_ip: "10.226.26.214",
    starttime: "2024-12-27 17:16:10",
    updatetime: "2025-01-21 15:56:05",
    level: "一般",
  },
  {
    alarm_name: "内存条状态为未识别",
    res_name: "JX-2015-HGT-X6-D09-PC-01",
    res_ip: "192.168.1.111",
    starttime: "2024-12-28 17:16:10",
    updatetime: "2025-01-21 15:56:05",
    level: "重要",
  },
  {
    alarm_name: "风扇状态为未识别",
    res_name: "JX-2017-HGT-X4-H06-PC",
    res_ip: "10.226.26.214",
    starttime: "2024-12-29 17:16:10",
    updatetime: "2025-01-21 15:56:04",
    level: "一般",
  },
  {
    alarm_name: "连通性为不连通",
    res_name: "JX-2017-HGT-X4-H06-PC",
    res_ip: "10.226.26.214",
    starttime: "2024-12-30 17:16:10",
    updatetime: "2025-01-21 15:56:04",
    level: "中等",
  },
  {
    alarm_name: "连通性为不连通",
    res_name: "JX-2017-HGT-X4-H06-PC",
    res_ip: "10.226.26.214",
    starttime: "2024-12-31 17:16:10",
    updatetime: "2025-01-21 15:56:04",
    level: "中等",
  },
  {
    alarm_name: "Agent或者SNMP服务连接异常",
    res_name: "LK-A2-403-SG-MG-ISCSI",
    res_ip: "10.226.19.23",
    starttime: "2025-01-01 17:16:10",
    updatetime: "2025-01-21 15:56:04",
    level: "重要",
  },
  {
    alarm_name: "风扇状态为未识别",
    res_name: "JX-2017-HGT-X4-H06-PC-04",
    res_ip: "10.226.26.214",
    starttime: "2025-01-02 17:16:10",
    updatetime: "2025-01-21 15:56:04",
    level: "一般",
  },
  {
    alarm_name: "温度状态为未识别",
    res_name: "JX-2017-HGT-X4-H11-PC-09",
    res_ip: "10.226.19.23",
    starttime: "2025-01-03 17:16:10",
    updatetime: "2025-01-21 15:56:04",
    level: "中等",
  },
  {
    alarm_name: "Ping连通性异常",
    res_name: "LK-A2-403-C19-RGS6250-TOR-1-A ",
    res_ip: "10.226.26.214",
    starttime: "2025-01-04 17:16:10",
    updatetime: "2025-01-21 15:56:04",
    level: "重要",
  },
  {
    alarm_name: "内存条状态为未识别",
    res_name: "JX-2017-HGT-X4-K05-PC-05",
    res_ip: "10.114.92.66",
    starttime: "2025-01-15 19:51:04",
    updatetime: "2025-01-21 15:56:04",
    level: "重要",
  },
  {
    alarm_name: "风扇状态为未识别",
    res_name: "JX-2017-HGT-X4-K05-PC-05",
    res_ip: "10.114.92.66",
    starttime: "2025-01-15 19:51:04",
    updatetime: "2025-01-21 15:56:04",
    level: "一般",
  },
];

import { axiosPostRequst, axiosGetRequst } from "./utils/request.js";

// 渲染图标
export const renderWarningBox = async () => {
  // var warningData = await axiosGetRequst("/m4");

  var iconsContainer = $("#warningA"); // 假设有一个容器元素
  warningData.forEach(function (item) {
    // 创建图标元素
    var icon = $("<i></i>");

    // 根据type设置图标的类和颜色
    switch (item.level) {
      case "中等":
        icon.addClass("layui-icon layui-icon-tips").css("color", "#FFB800"); // 黄色
        break;
      case "重要":
        icon
          .addClass("layui-icon layui-icon-tips-fill")
          .css("color", "#FF5722"); // 红色
        break;
      default:
        icon.addClass("layui-icon layui-icon-tips").css("color", "#999"); // 默认颜色
        break;
    }
    var iconWrap = $('<li class="icon-wrap"></li>');
    // 主机
    var host = $("<span class='icon-wrap-host'></span>").text(item.res_name);
    // 告警名称
    var alarm_text = $("<span  class='icon-wrap-alarm'></span>").text(
      item.alarm_name
    );
    // // 发生时间
    // var text = $("<span></span>").text(item.updatetime);

    // 将图标和文本添加到包裹元素中
    iconWrap.append(icon).append(host).append(alarm_text);

    // 将包裹元素添加到容器中
    iconsContainer.append(iconWrap);
  });
};

export const renderWarningTable = async () => {
  // var warningData = await axiosGetRequst("/m4");

  layui.use("table", function () {
    var table = layui.table;
    var theight = $(".warning-table").height();
    // 创建渲染实例
    table.render({
      elem: "#ID-table-demo-page",
      // url: "/m3", // 此处为静态模拟数据，实际使用时需换成真实接口
      data: warningData,
      size: "sm",
      page: {
        // 支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
        layout: ["limit", "count", "prev", "page", "next", "skip"], //自定义分页布局
        //curr: 5, //设定初始在第 5 页
        groups: 1, //只显示 1 个连续页码
        first: false, //不显示首页
        last: false, //不显示尾页
      },
      pagebar: "#ID-table-demo-page-pagebar", // 分页栏模板
      cols: [
        [
          { field: "alarm_name", title: "告警信息", sort: true },
          { field: "res_ip", title: "资源IP", sort: true },
          { field: "starttime", title: "告警时间", sort: true },
          { field: "updatetime", title: "最新时间", sort: true },
          { field: "level", title: "告警等级", sort: true },
        ],
      ],
      height: theight > 400 ? theight - 60 : theight,
    });
    // 底部分页栏事件
    table.on("pagebar(ID-table-demo-page)", function (obj) {
      var eventValue = obj.event; // 获得按钮 lay-event 值
      layer.msg(eventValue);
    });
  });
};
